//
// Created by hjie on 23-10-3.
//
#include <cstring>
#include <string>
#include "rtp_parser/rtp_frame.h"
#include "rtp_parser/rtp_parser.h"
#include "./../../loop_event/loop_event_define.h"


static uint32_t count = 0;

void OnMessageFunc(UdpPacket * packet)
{
    char buffer[128] = {0};
    inet_ntop(AF_INET, &packet->sai.sin_addr, buffer, 128);
    printf("data size : %d and from : %s and packet count : %d.\n", packet->length, buffer, count++);

    int index = 0;
    RtpFrame frame{};
    RtpParser parser;
    bool result = parser.ParseRtpFrame(packet->data, packet->length, index, frame);
    if (result)
    {
        PrintRtpHeader(frame.m_header);
    }
}

int main(int argc, const char * argv[])
{
    LoopEvent loop_event;
    auto * server = new UdpServer(&loop_event);

    server->SetUdpMessage(OnMessageFunc);

    server->Listen(5004);
    loop_event.Run();
    return EXIT_SUCCESS;
}
